import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { HttpExceptionFilter } from "./filters/http-exception.filter";
import * as requestIp from 'request-ip';
import { ValidationPipe } from "@nestjs/common";


async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.setGlobalPrefix('api-v1');
  app.useGlobalFilters(new HttpExceptionFilter());
  app.useGlobalPipes(new ValidationPipe());
  app.use(requestIp.mw())
  app.enableCors();


  // swagger配置
  const config = new DocumentBuilder()
    .setTitle('mall商城c端api')
    .setDescription('mall商城c端api')
    .setVersion('1.0')
    .addBasicAuth({
      description: "用户token",
      name: "token",
      type: 'apiKey',
      in: 'header'
    }, "token")
    .build();
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('api', app, document);

  await app.listen(5000);
}
bootstrap();
